{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "05136201",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "282214de",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-21T06:25:32.417717Z",
     "start_time": "2021-07-21T06:25:26.717370Z"
    },
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "import h2o\n",
    "from h2o.automl import H2OAutoML\n",
    "h2o.init()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9379ab1b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-21T06:25:32.423468Z",
     "start_time": "2021-07-21T06:25:32.420319Z"
    }
   },
   "outputs": [],
   "source": [
    "train_path = './data/zhidemai/train.csv'\n",
    "test_path = './data/zhidemai/test.csv'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "596d6bf3",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-21T06:25:37.579074Z",
     "start_time": "2021-07-21T06:25:32.426142Z"
    }
   },
   "outputs": [],
   "source": [
    "# Load data into H2O\n",
    "train = h2o.import_file(train_path)\n",
    "test  = h2o.import_file(test_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "39c96865",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-21T06:25:37.917394Z",
     "start_time": "2021-07-21T06:25:37.583696Z"
    },
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7db320a9",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-21T06:25:37.923894Z",
     "start_time": "2021-07-21T06:25:37.920236Z"
    }
   },
   "outputs": [],
   "source": [
    "y = \"orders_3h_15h\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e0c0fded",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-21T08:15:57.152703Z",
     "start_time": "2021-07-21T06:25:37.926660Z"
    },
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "aml2 = H2OAutoML(max_runtime_secs = 7200, seed = 1, project_name = \"powerplant_full_data\")\n",
    "aml2.train(y = y, training_frame = train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3078dfcb",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-21T08:15:59.077075Z",
     "start_time": "2021-07-21T08:15:57.154815Z"
    },
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "pred = aml2.predict(test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b0bae73a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-21T08:16:00.448800Z",
     "start_time": "2021-07-21T08:16:00.096734Z"
    }
   },
   "outputs": [],
   "source": [
    "sub = pd.read_csv(test_path)\n",
    "sub = sub[['article_id']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ad8e3bc7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-21T08:16:00.873416Z",
     "start_time": "2021-07-21T08:16:00.451042Z"
    },
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "pred = h2o.as_list(pred)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9d7c0c70",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-21T08:16:00.882590Z",
     "start_time": "2021-07-21T08:16:00.877198Z"
    },
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "sub['orders_3h_15h'] = pred['predict']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c6e4612c",
   "metadata": {},
   "outputs": [],
   "source": [
    "sub.to_csv(\"./h2o_sub.csv\", index = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "026524ae",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.10"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
